package com.peng.test;

import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;

import lombok.Data;

/**
 * SpringBeanUtilSample
 *
 * 会将 null的属性直接复制给target 对象
 *
 * @author lupeng
 * Created on 2022-04-27
 */
public class SpringBeanUtilSample {

    private static final Logger logger = LoggerFactory.getLogger(SpringBeanUtilSample.class);

    @Test
    public void s1() {
        B b = new B();
        b.setFirstName("zhang");
        b.setLastName("san");

        A a = new A();
        a.setLastName("gouzi");

        BeanUtils.copyProperties(a, b);

        System.out.println(b);
    }


    @Data
    static class A {
        private String firstName;

        private String lastName;
    }

    @Data
    static class B {
        private String firstName;

        private String lastName;
    }

}
